package my.avoskagae.client.view.gwt;

import my.avoskagae.client.presenter.IProductDetailPresenter;
import my.avoskagae.client.view.IProductDetailView;
import my.avoskagae.model.entity.Product;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.mvp4g.client.view.ReverseViewInterface;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Label;

public class ProductDetailView extends Composite implements IProductDetailView, ReverseViewInterface<IProductDetailPresenter>{

	IProductDetailPresenter presenter;
	
	public IProductDetailPresenter getPresenter() {
		return presenter;
	}

	public void setPresenter(IProductDetailPresenter presenter) {
		this.presenter = presenter;
	}

	private static ProductDetailViewUiBinder uiBinder = GWT
			.create(ProductDetailViewUiBinder.class);
	@UiField Label name;
	@UiField Label needPurchase;

	interface ProductDetailViewUiBinder extends
			UiBinder<Widget, ProductDetailView> {
	}

	public ProductDetailView() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	
	
	
	@Override
	public void refreshData(Product product) {
		if (product!=null){
			this.name.setText(product.getName());
			this.needPurchase.setText(product.getNeedPurchase()?"Необходимо купить":"Не нужно покупать");
		} else {
			this.name.setText("");
			this.needPurchase.setText("");
		}
				
	}

	@Override
	public IsWidget getWidgetItself() {
		return this;
	}

}
